package it.struts.helloworld.action;

//import it.struts.helloworld.dao.LoginDAO;
import it.struts.helloworld.form.NewUserForm;
//import it.struts.helloworld.model.Utenti;
import it.struts.helloworld.services.NewUserService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class NewUserAction extends Action {
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest req, HttpServletResponse res) throws Exception {
		
		HttpSession ses = req.getSession(true);
		String target = null;

		
		NewUserForm nf = (NewUserForm)form;
		String n = nf.getName();
		String c = nf.getSurname();
		String d = nf.getBirthday();
		String f = nf.getCodeF();
		String i = nf.getAddress();
		String m = nf.geteMail();
		String u = nf.getUserName();
		String p = nf.getPassword();
	


		NewUserService nus = new NewUserService();
		nus.addNewUtente(n, c, d, f, i, m, u, p);

		ses.setAttribute("s", n);

		if (n.equals("")) {
			target = "failure";
			req.setAttribute("us", "Registrazione non eseguita!");
		}
		
		target = "success";
		req.setAttribute("us", "Nuovo utente registrato!");
		return map.findForward("success");
		
	}
}
